from pms.common.views import PostFormula
from project.models import ProjectRole
from project.utils.role import project_role_permissions


class API(PostFormula):
    def handle(self, req):
        pid = req['id']
        project_roles = [{
            'id': project_role.id,
            'name': project_role.name,
            'permissions': project_role_permissions(project_role)
        } for project_role in ProjectRole.objects.filter(pid=pid)]
        return self.success_respond({
            'list': project_roles
        })
